Skip to content

fix(core): avoid stale length in native suffix reads - #9225

Merged
Xuanwo merged 1 commit into
mainfrom
xuanwo/fix-stale-reader-suffix-length
Nov 27, 2026
Merged

Xuanwo merged 1 commit into
mainfrom
xuanwo/fix-stale-reader-suffix-length

Conversation

@Xuanwo

@Xuanwo Xuanwo commented Nov 27, 2026

Copy link
Copy Markdown
Member

Which issue does this PR close?

Part of #9196. Follow-up to #9220.

Rationale for this change

A reused Reader can reject valid suffix data after an overwrite if the current response omits the total file length. In the HTTP loopback test, a first range read observes a two-byte file. The same reader then sends Range: bytes=-4 and receives 206 Partial Content with an unknown total. After growth to six bytes, Content-Range: bytes 2-5/* returns cdef, which #9220 rejects as too much data. After a shrink to one byte, Content-Range: bytes 0-0/* returns z, which #9220 rejects as too little data. Both errors use the cached length of two. RFC 9110 §14.4

What changes are included in this PR?

BufferStream requires exactly min(n, file_length) bytes when the current suffix response supplies the file length. With no file length in that response, it caps the read at n and accepts a clean EOF below that bound. This uses the existing open reply without an extra stat.

The loopback test also checks that the default reader surfaces a framing error when all requested bytes arrive but the final HTTP chunk marker is missing. The existing RetryLayer behavior treats a temporary stream error after the requested byte count as EOF.

Are there any user-facing changes?

Applications can reuse a Reader for native suffix reads across size changes, and Reader::metadata() continues to expose the first observed metadata. Chunked suffix reads, FuturesAsyncReader suffix reads, and open-ended range planning remain part of #9196.

Breaking changes

AI Usage Statement

  • Harness pi via T3, model magpie/codex/gpt-6.2-astra, effort high. Traced the remaining suffix failure and scoped the follow-up.
  • Harness pi via T3, model magpie/codex/gpt-6.2-sol, effort max. Implemented the core fix and reproduced the failure through the public HTTP reader against a local origin.
  • Harness pi via T3, model magpie/agy-cli/gemini-4-neon, effort high. Independently reviewed the signed change and drafted the PR description.

Use the file length from the suffix open to enforce an exact size. If that response omits the file length, enforce the requested upper bound and let the underlying stream validate response completeness.
@Xuanwo Xuanwo added the releases-note/fix The PR fixes a bug or has a title that begins with "fix" label Nov 27, 2026
@Xuanwo
Xuanwo requested a review from PsiACE November 27, 2026 00:33
@github-actions github-actions Bot added core size:M This PR changes 30-99 lines, ignoring generated files. labels Nov 27, 2026
@Xuanwo
Xuanwo merged commit b547c1e into main Nov 27, 2026
114 checks passed
@Xuanwo
Xuanwo deleted the xuanwo/fix-stale-reader-suffix-length branch November 27, 2026 01:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core releases-note/fix The PR fixes a bug or has a title that begins with "fix" size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants